//
//  LZLoginTitleView.m
//  laziz_Merchant
//
//  Created by ZhaoDongBo on 2016/11/22.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZLoginTitleView.h"
#import "Masonry.h"

@implementation LZLoginTitleView

- (instancetype)initWithViewType:(LZLOGINTITLEVIEW_TYPE)type {
    self = [super init];
    if (self) {
        self.type = type;
        [self setup];
        [self addAutoLayout];
    }
    return self;
}

- (void)setup {

    if (self.type == LZLOGINTITLEVIEW_TYPE_LOGIN) {
        [self addSubview:self.titleImage];
        [self addSubview:self.titleLabel];
    }
    else {
        [self addSubview:self.titleImage];
        [self addSubview:self.titleLabel];
        [self addSubview:self.subLabel];
    }
}

- (void)addAutoLayout {

    WS(weakSelf);
    
    if (self.type == LZLOGINTITLEVIEW_TYPE_LOGIN) {
        [self.titleImage makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.centerX.mas_equalTo(weakSelf.centerX);
            make.size.mas_equalTo(CGSizeMake(47, 47));
        }];
        
        [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakSelf.titleImage.mas_bottom).with.offset(15);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(20);
        }];
    }
    else {
        [self.titleImage makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.centerX.mas_equalTo(weakSelf.centerX);
            make.size.mas_equalTo(CGSizeMake(47, 47));
        }];
        
        [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakSelf.titleImage.mas_bottom).with.offset(15);
            make.leading.mas_equalTo(0);
            make.trailing.mas_equalTo(0);
            make.height.mas_equalTo(20);
        }];
        
        [self.subLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(weakSelf.titleLabel.mas_bottom).with.offset(10);
            make.leading.mas_equalTo(10);
            make.trailing.mas_equalTo(-10);
        }];
    }
}

- (UIImageView *)titleImage {

    if (_titleImage == nil) {
        _titleImage = [[UIImageView alloc] init];
    }
    
    return _titleImage;
}

- (UILabel *)titleLabel {

    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor       = UIColorFromRGB(0xfffefe, 1);
        _titleLabel.textAlignment   = NSTextAlignmentCenter;
        _titleLabel.font            = [UIFont fontWithName:@"Menlo-Italic" size:17];
    }
    
    return _titleLabel;
}

- (UILabel *)subLabel {

    if (_subLabel == nil) {
        _subLabel = [[UILabel alloc] init];
        _subLabel.textColor     = UIColorFromRGB(0x999999, 1);
        _subLabel.textAlignment = NSTextAlignmentCenter;
        _subLabel.font          = [UIFont fontWithName:@"Arial-ItalicMT" size:15];
        _subLabel.numberOfLines = 2;
    }
    
    return _subLabel;
}
@end
